package com.transaction.demo.springdemo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.stereotype.Component;

@Component
public class ClassA {
    private ClassB classB;
 
    @Autowired
    public void setClassB(ClassB classB) {
        this.classB = classB;
    }
 
    public void print() {
        System.out.println("ClassA");
    }
}
 
 
@Component
class ClassB {
    private ClassA classA;
 
    @Autowired
    public void setClassA(ClassA classA) {
        this.classA = classA;
    }
 
    public void print() {
        System.out.println("ClassB");
    }
}
 
 
@SpringBootApplication
class Application {
 
	public static void main(String[] args) {
		ConfigurableApplicationContext context = SpringApplication.run(Application.class, args);
 
		// 尝试获取 ClassA、ClassB 和 ClassC 的实例
		ClassA classA = context.getBean(ClassA.class);
		ClassB classB = context.getBean(ClassB.class);
 
		// 调用 print 方法，查看输出
		classA.print();
		classB.print();
	}
 
}